package com.ruoyi.base.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.base.domain.BaseSection;
import com.ruoyi.base.service.IBaseSectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 节次Controller
 * 
 * @author yepanpan
 * @date 2020-11-09
 */
@Api("节次信息管理")
@RestController
@RequestMapping("/base/section")
public class BaseSectionController extends BaseController
{
    @Autowired
    private IBaseSectionService baseSectionService;

    /**
     * 查询节次列表
     */
    @ApiOperation("获取节次列表")
    @PreAuthorize("@ss.hasPermi('base:section:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseSection baseSection)
    {
        startPage();
        List<BaseSection> list = baseSectionService.selectBaseSectionList(baseSection);
        return getDataTable(list);
    }

    /**
     * 查询节次列表
     */
    @ApiOperation("获取节次列表")
    @GetMapping("/select")
    public TableDataInfo select(BaseSection baseSection)
    {
        List<BaseSection> list = baseSectionService.selectBaseSectionList(baseSection);
        return getDataTable(list);
    }


    /**
     * 导出节次列表
     */
    @ApiOperation("导出节次列表")
    @PreAuthorize("@ss.hasPermi('base:section:export')")
    @Log(title = "节次", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BaseSection baseSection)
    {
        List<BaseSection> list = baseSectionService.selectBaseSectionList(baseSection);
        ExcelUtil<BaseSection> util = new ExcelUtil<BaseSection>(BaseSection.class);
        return util.exportExcel(list, "section");
    }

    /**
     * 获取节次详细信息
     */
    @ApiOperation("获取节次详细信息")
    @ApiImplicitParam(name = "id", value = "节次ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('base:section:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseSectionService.selectBaseSectionById(id));
    }

    /**
     * 新增节次
     */
    @ApiOperation("新增节次")
    @PreAuthorize("@ss.hasPermi('base:section:add')")
    @Log(title = "节次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseSection baseSection)
    {
        return toAjax(baseSectionService.insertBaseSection(baseSection));
    }

    /**
     * 修改节次
     */
    @ApiOperation("修改节次")
    @PreAuthorize("@ss.hasPermi('base:section:edit')")
    @Log(title = "节次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseSection baseSection)
    {
        return toAjax(baseSectionService.updateBaseSection(baseSection));
    }

    /**
     * 删除节次
     */
    @ApiOperation("删除节次")
    @ApiImplicitParam(name = "id", value = "节次ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('base:section:remove')")
    @Log(title = "节次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseSectionService.deleteBaseSectionByIds(ids));
    }
}
